package com.jy.api.dao;

import com.jy.api.domain.StockChangeReason;
import com.jy.api.domain.StockLevel;
import com.jy.api.domain.StockReceipt;
import com.jy.api.domain.StockType;
import com.jy.api.signUpReq.InvStatisticsRes;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

/**
 * Created by xiaohua on 2018/7/12.
 */
public interface StockReceiptDao extends CrudRepository<StockReceipt, Long> {


    Page<StockReceipt> findListByLevelAndStoreId(StockLevel level, String storeId, Pageable pageable);

    Page<StockReceipt> findByStoreIdAndAddTimeBetweenAndType(String storeId, Date begin, Date end, StockType type, Pageable pageable);

    @Query(value = "SELECT sum(`amount`), SUM(`quantity`) qty FROM `stock_receipt`  WHERE `store_id`= ?1 AND `type`= ?2 AND `stock_source`= ?3 AND `add_time` LIKE CONCAT(?4,'%')", nativeQuery = true)
    List<Object[]> findStatistics(String storeId, String type, String reason,String time);
}
